﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace csdemo
{
    class fpengine
    {
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern int SetMsgMainHandle(IntPtr hWnd);

        //打开设备
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern int OpenDevice(int nPortNum, int nPortPara, int nDeviceType);

        //连接设备
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern int LinkDevice();

        //关闭设备
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern int CloseDevice();

        //获取图像
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern void CaptureImage();

        //获取特征点（采集一次手指）
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern void GenFpChar();

        //登记指纹模板（采集两次手指）
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern void EnrolFpChar();

        //获取工作消息
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern int GetWorkMsg();

        //获取返回消息
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern int GetRetMsg();

        //释放消息
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern int ReleaseMsg();

        //获取特征点
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern int GetFpCharByGen(ref byte pRefVal, ref int pRefSize);

        //获取指纹模板
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern int GetFpCharByEnl(ref byte pRefVal, ref int pRefSize);

        //获取特征点（Ansi编码字符串）
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern int GetFpStrByGen(ref byte pRefVal);

        //获取指纹模板（Ansi编码字符串）
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern int GetFpStrByEnl(ref byte pRefVal);

        //从图象获取特征点
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern int CreateTemplate(ref byte pFingerData, ref byte pTemplate);

        //比对两个特征点
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern int MatchTemplate(ref byte pSrcData, ref byte pDstData);

        //比对两个特征点（Ansi编码字符串）
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        //public static extern int MatchTemplateEx(ref byte pSrcData, ref byte pDstData);
        public static extern int MatchTemplateEx(ref byte pDstData, ref byte pSrcData);

        //获取图像(RAW)
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern int GetImage(ref byte imagedata, ref int size);

        //设置图像(RAW)
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern int SetImage(ref byte imagedata, int size);

        //画指纹图像
        [System.Runtime.InteropServices.DllImport("fpengine.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern int DrawImage(IntPtr hdc, int left, int top);


        public const int FPDATASIZE = 256;
        public const int IMGWIDTH = 256;
        public const int IMGHEIGHT = 288;
        public const int IMGSIZE = 73728;

        //窗口消息
        public const int WM_FPMESSAGE = 1024 + 120;             //自定义消息
        public const int FPM_DEVICE=0x01;			//状态提示
        public const int FPM_PLACE=0x02;			//请按手指
        public const int FPM_LIFT=0x03;			  //请抬起手指
        public const int FPM_CAPTURE=0x04;		//采集图像
        public const int FPM_ENROLL=0x06;			//登记指纹模版
        public const int FPM_GENCHAR=0x05 ;    //采集特征点
        public const int FPM_NEWIMAGE=0x07;		//指纹图像
        public const int RET_OK=0x1;
        public const int RET_FAIL=0x0;
           
    }
}
